<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript">
        $(function() { $('#selectedDateTime').datetimepicker(); });
        </script>
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/jquery-ui.min.js"></script>
        <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/hot-sneaks/jquery-ui.css" />
        <script src="pathtojs/jquery-ui-timepicker-addon.js"></script>
    </head>
    <body>
        
        <f:view>
            <h:form id="login_frm">
                          
                         
                <table width="800" border="1" cellspacing="0" cellpadding="2">
                  <tr>
                    <td width="70" align="center">New User:</td>     
                    <td width="180" align="center"><h:outputText value="Username: "/>
                    <h:inputText id="username" value="#{add_user.username}" required="true" styleClass="input_text"/></td>
                  
                    <td width="180" align="center"><h:outputText value="Password: "/>
                    <h:inputSecret id="password" value="#{add_user.password}" required="true" styleClass="input_text"/></td>
                  
                    <td width="150" align="center"><h:outputText value="Authority: "/>
                    <h:selectOneMenu id="subscriptions" value="#{add_user.authority}">
                    <f:selectItem id="Admin" itemLabel="Admin" itemValue="Admin" />
                    <f:selectItem id="User" itemLabel="User" itemValue="User" />
                    <f:selectItem id="Viewer" itemLabel="Viewer" itemValue="Viewer" />
                    </h:selectOneMenu>
                    </td>
                    <td width="80" align="center">
                    <h:commandButton action="#{add_user.submitUser}" value="submit" type="submit"/>
                    
                    </td>    
                  </tr>
                  
                </table>
                
            </h:form>
     
            <h:form>
        <table width="800" border="1" cellspacing="0" cellpadding="2" style="margin-top: 20px">
            <tr>
              <td rowspan="2" width="70" align="center" >New Event:</td>
              <td align="center">Format:<br/>yyyy-mm-dd hh:mm:ss</td>
              <td width="365" align="center"><h:outputText value="StartTime: "/>
              <h:inputText id="selectedDateTime" value="#{add_event.starttime}" required="true"/></td>
              <td width="365" align="center"><h:outputText value="EndTime: "/>
              <h:inputText id="endtime" value="#{add_event.endtime}" required="true" /></td>
              <td width="365" align="center"><h:outputText value="Assignees: "/>
              <h:inputText id="assignees" value="#{add_event.assignees}" required="true" /></td>
             
            </tr>
            <tr>
              <td width="200" align="center"><h:outputText value="Supervisor: "/>
              <h:inputText id="superviosor" value="#{add_event.supervisor}" required="true" /></td>
              <td width="200" align="center"><h:outputText value="EventName: "/>
              <h:inputText id="eventname" value="#{add_event.eventname}" required="true" /></td>

              <td width="150" align="center"><h:outputText value="Duration: "/>
              <h:selectOneMenu id="duration" value="#{add_event.duration}">
              <f:selectItem itemLabel="15mins" itemValue="15" />
              <f:selectItem itemLabel="30mins" itemValue="30" />
              <f:selectItem itemLabel="45mins" itemValue="45" />
              <f:selectItem itemLabel="60mins" itemValue="60" />
              <f:selectItem itemLabel="90mins" itemValue="90" />
              <f:selectItem itemLabel="120mins" itemValue="120" />
              <f:selectItem itemLabel="180mins" itemValue="180" />
              </h:selectOneMenu>
              </td>
              <td width="80" align="center">
              <h:commandButton action="#{add_event.submitEvent}" value="submit" type="submit"/>
              </td>
            </tr>

          </table>
          </h:form>
        </f:view>
                    
        <table width="800" border="1" cellspacing="0" cellpadding="2" style="margin-top: 20px">
        <%@ page import="java.util.*" %>
        <%@ page import="javax.sql.*;" %>
        <% 

        java.sql.Connection con;
        java.sql.Statement s;
        java.sql.ResultSet rs;
        java.sql.PreparedStatement pst;

        con=null;
        s=null;
        pst=null;
        rs=null;

        // Remember to change the next line with your own environment 
        String url= 
        "jdbc:mysql://localhost:3306/db_jsf";
        String id= "root";
        String pass = "";
        try{

        Class.forName("com.mysql.jdbc.Driver");
        con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/db_jsf","root","");

        }catch(ClassNotFoundException cnfex){
        cnfex.printStackTrace();

        }
        String sql = "SELECT * FROM db_jsf.event";
        try{
        s = con.createStatement();
        rs = s.executeQuery(sql);
        %>
        <tr>
            <td>ID</td>
            <td>Event Name</td>
            <td>Start Time</td>
            <td>End Time</td>
            <td>Duration(min)</td>
            <td>Surpervisor</td>
            <td>detail</td>
        </tr>
        <%
        while( rs.next() ){
        %><tr>
        <td><%= rs.getString("ID") %></td>
        <td><%= rs.getString("EventName") %></td>
        <td><%=rs.getString(2).toString()%></td>
        <td><%=rs.getString(3).toString()%></td>
        <td><%=rs.getString(4).toString()%></td>
        <td><%=rs.getString(5).toString()%></td>
        <td><button type="button">Details</button></td>
        </tr>
        <%
        }
        %>

        <%

        }
        catch(Exception e){e.printStackTrace();}
        finally{
        if(rs!=null) rs.close();
        if(s!=null) s.close();
        if(con!=null) con.close();
        }

        %>

                 
        </tr>
                  
     
        </table>
    </body>
</html>